package cn.yougou.serviceImpl;

import cn.yougou.dto.Query;
import cn.yougou.mapper.YgUserMapper;
import cn.yougou.pojo.YgUser;
import cn.yougou.pojo.YgUserBasicsinfo;
import cn.yougou.service.user.YgUserService;
import cn.yougou.vo.YgPersonalVo;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.UUID;

/**
 * (YgUser)表服务实现类
 *
 * @author makejava
 * @since 2020-12-04 14:58:21
 */
@Service
public class YgUserServiceImpl implements YgUserService {

    @Autowired
    private YgUserMapper ygUserMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param
     * @return 实例对象
     */
    @Override
    public YgUser queryById(Integer id) {
        return this.ygUserMapper.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<YgUser> queryAllByLimit(int offset, int limit) {
        return this.ygUserMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param ygUser 实例对象
     * @return 实例对象
     */
    @Override
    public YgUser insert(YgUser ygUser) {
        this.ygUserMapper.insert(ygUser);
        return ygUser;
    }


    /**
     * 修改数据
     *
     * @param ygUser 实例对象
     * @return 实例对象
     */

    @Override
    public int update(YgUser ygUser) {

        return this.ygUserMapper.update(ygUser);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.ygUserMapper.deleteById(id) > 0;
    }


    @Override
    public List<YgUser> queryAll(YgUser ygUser) {
        return null;
    }

    @Override
    public int selCount(Query query) {

        return ygUserMapper.selCount(query);
    }

    @Override
    public List<YgUser> conditionSelAll(Query query) {

        return ygUserMapper.conditionSelAll(query);
    }



    //登录
    @Override
    public YgUser login(YgUser ygUser) {
        return ygUserMapper.login(ygUser);
    }

    //注册
    @Override
    public Integer add(String phone, String password) {

        YgUser yg = new YgUser();
        ygUserMapper.add(phone, password);
        System.out.println(yg.getId());
        return 1;
    }

    @Override
    public List<YgPersonalVo> selPersonal(YgPersonalVo ygPersonalVo) {
        return ygUserMapper.selPersonal(ygPersonalVo);
    }

    /*
    * 通过主键 为用户充值
    * */
    public int chargeMoney(YgUser ygUser){
        return ygUserMapper.chargeMoney(ygUser);
    }

    /**
     * 通过主键扣除用户余额
     * @param ygUser
     * @return
     */
    @Override
    public int reduceBalance(YgUser ygUser) {
        return ygUserMapper.reduceBalance(ygUser);
    }
}